home *** CD-ROM | disk | FTP | other *** search
- // PCX
- // (C) Anubis Software, Junio 1995
- #ifndef PCX
- #define PCX
-
- // --------------------------------------+
- // Inclusión de librerías estandares |
- // --------------------------------------+
- #include <stdio.h>
- #include <alloc.h>
-
- // --------------------------------------+
- // Inclusion de librerias Anubis Soft |
- // --------------------------------------+
- #include "mdefs.h"
- #include "grafic1.h"
-
- // --------------------------------------+
- // Definición de los tipos de datos |
- // --------------------------------------+
- typedef struct {
- BYTE Fabricante; // El fabricante 10=ZSoft.PCX
- BYTE Version; // (0..5)
- BYTE Codificacion; // (1) Run Length
- BYTE BitsPixel; // (1,2,4,8) Número de colores.
- WORD Xmin;
- WORD Ymin;
- WORD Xmax;
- WORD Ymax;
- WORD HDpi;
- WORD VDpi;
- BYTE Color[48];
- BYTE Res; // =0
- BYTE NPlanes;
- WORD BytesLine;
- WORD PaletteInfo;
- WORD HscreenSize;
- WORD VscreenSize;
- BYTE Relleno[54];
- } PCXCab;
-
- typedef struct {
- PCXCab Cabecera;
- PBYTE *Datos;
- PBYTE *Paleta;
- } pcx256;
-
- // ------------------------------------+
- // Declaración de variables globales |
- // ------------------------------------+
-
- // ------------------------------------+
- // Declaración de prototipos de la lib |
- // ------------------------------------+
- boolean LeePCX (pcx256 *, char *);
- void PonPCX(pcx256 *, int, int);
- void PonmaskPCX(pcx256 *, int, int, BYTE);
- boolean PonfPCX(char *, int, int);
-
- // ------------------------------------+
- // Implementacion de los prototipos |
- // ------------------------------------+
- boolean LeePCX (pcx256 *imagen, char *fichero)
- {
- FILE *fp;
- int fin;
-
- if((fp=fopen(fichero,"rb"))!=NULL) {
- fread(&((*imagen).Cabecera),sizeof(PCXCab),1,fp);
- if((*imagen).Cabecera.BitsPixel == 8) {
- fseek(fp,-768,SEEK_END);
- (*imagen).Paleta = malloc(768);
- fread( (*imagen).Paleta, 768, 1, fp);
- fin=ftell(fp);
- (*imagen).Datos = malloc(fin);
- rewind(fp);
- fseek(fp,128,0);
- fread( (*imagen).Datos, fin, 1, fp);
- }// end if
- return(TRUE);
- } else {
- return(FALSE);
- }// end if
- }// end LeePCX
-
-
- void PonPCX (pcx256 *imagen,int Xini,int Yini)
- {
- int ancho=(*imagen).Cabecera.Xmax - (*imagen).Cabecera.Xmin;
- int alto =(*imagen).Cabecera.Ymax - (*imagen).Cabecera.Ymin;
- PBYTE ch =(PBYTE) (*imagen).Datos;
- BYTE rep;
- int x=0,y=0,con;
-
- while( (x<ancho) || (y<alto)) {
- if ( (*ch & 192) == 192) {
- rep= *ch & 63;
- ch++;
- }// end if
- for( con=0;con<rep;con++) {
- ActPunto (Xini+x,Yini+y,*ch);
- x++;
- if(x>ancho) {
- x=0;
- y++;
- }// end if
- }// end for
- rep=1;
- ch++;
- }// end while
- }// end PonPCX
-
- void PonmaskPCX (pcx256 *imagen,int Xini,int Yini,BYTE mask)
- {
- int ancho=(*imagen).Cabecera.Xmax - (*imagen).Cabecera.Xmin;
- int alto =(*imagen).Cabecera.Ymax - (*imagen).Cabecera.Ymin;
- PBYTE ch =(PBYTE) (*imagen).Datos;
- BYTE rep;
- int x=0,y=0,con;
-
- while( (x<ancho) || (y<alto)) {
- if ( (*ch & 192) == 192) {
- rep= *ch & 63;
- ch++;
- }// end if
- for( con=0;con<rep;con++) {
- if (*ch != mask)
- ActPunto (Xini+x,Yini+y,*ch);
- x++;
- if(x>ancho) {
- x=0;
- y++;
- }// end if
- }// end for
- rep=1;
- ch++;
- }// end while
- }// end PonmaskPCX
-
- boolean PonfPCX(char *fichero, int Xini, int Yini)
- {
- int x1, x2, y1, y2, x, y;
- char dato[2000];
- register int zx,zy;
- char rep=1;
- char con;
- char ch;
- FILE *fp;
-
- if( (fp=fopen(fichero,"rb"))==NULL) return(FALSE);
- fseek(fp,4,0);
- x1=getw(fp);
- y1=getw(fp);
- x2=getw(fp);
- y2=getw(fp);
- x=x2-x1;
- y=y2-y1;
- fseek(fp,128,0);
- zx=0,zy=0;
- while(feof(fp)==0) {
- ch=getc(fp);
- if (feof(fp) != 0) goto end;
- if((ch&192)==192) {
- rep=(ch&63);
- ch=getc(fp);
- }// end if
- for(con=0;con<rep;con++) {
- ActPunto(Xini+zx++,Yini+zy,ch);
- if(zx>x) {
- zy++,zx=0;
- } // end if
- if (zy>y) goto end;
- }// end for
- rep=1;
- }// end while
- end:
- fclose(fp);
- return(TRUE);
- }// end PonfPCX
-
- /*
- main(int argc, char *argv[])
- {
- pcx256 dibujo;
- int x=4,y;
-
- modo320200();
- InitMouse(0xFF);
- show_mouse();
- ide_mouse();
- PonfPCX("dibujo.pcx",0,0);
- if (argc ==2) {
- LeePCX(&dibujo,argv[1]);
- while((estado & BUTTON_LEFT)==0) {
- x=mousex;
- y=mousey;
- PonmaskPCX(&dibujo,x,y,255);
- }// end while
- }// end if
- return(0);
- }
- */
- #endif
-
-
-